# -*- encoding: utf-8 -*-

from memory import ESP, EBP

class Leave(object):

    """ Classe définissant une instruction Push Ra. """

    def __init__ (self,mem):
        self.__mem  = mem

    def do (self):
        ebp = self.__mem.getRegister(EBP)
        if ebp + 1 == 256:
            raise Exception("End of stack reached.")
        self.__mem.setRegister(ESP, ebp)
        self.__mem.setRegister(
            num = EBP,
            newVal = self.__mem.getRamAt(ebp)
            )
        self.__mem.setRegister(ESP, ebp + 2)
        return self.__mem.getRamAt(ebp + 1)

    def __str__ (self):
        return "leave" 

    def __unicode__ (self):
        return self.__str__ () 
